OTSnd
Sends data to a remote peer.C INTERFACE
OTResult OTSnd (EndpointRef ref, void* buf, size_t nbytes, OTFlags flags);C++ INTERFACE
OTResult TEndpoint::Snd(void* buf, size_t nbytes, OTFlags flags);PARAMETERS
ref
- The endpoint reference of the endpoint sending data.
buf
- A pointer to the data being sent. If you are sending data that is not stored contiguously, this is a pointer to an
OTData
structure that describes the first data fragment.nbytes
- A long specifying the number of bytes being sent. If you are sending data that is not stored contiguously, you must set this field to the
kNetbufDataIsOTData
constant.flags
- A long bitmapped variable specifying whether the data to be sent is expedited (
T_EXPEDITED
) and whether more data remains to be sent (T_MORE
). To set both fields, use thebitAND
operator.DESCRIPTION
You use theOTSnd
function to send data to a remote peer. Before you use this function, you must establish a connection with the peer.If the
OTSnd
function succeeds, it returns an integer (OSStatus
) specifying the number of bytes that were actually sent. If it fails, it returns a negative integer corresponding to a result code that indicates the reason for the failure.You specify the data to be sent by passing a pointer to the data (
buf
) and by specifying the size of the data (nbytes
). The maximum size of the data you can send is specified by thetsdu
field of theTEndpointInfo
structure for the endpoint.Some protocols use expedited data for control or attention messages. To determine whether the endpoint supports this service, examine the
etsdu
field of theTEndpointInfo
structure. A positive integer for theetsdu
field indicates the maximum size in bytes of expedited data that you can send. To send expedited data, you must set theT_EXPEDITED
bit of theflags
parameter.If you want to break up the data sent into smaller logical units, you can set the
T_MORE
bit of theflags
parameter to indicate that you are using additional calls to theOTSnd
function to send more data that belongs to the same logical unit.
To indicate that the last data unit is being sent, you must specify 0 fornbytes
and turn off theT_MORE
flag. This is the only circumstance under which it is permitted to send a zero-length data unit. If the endpoint does not support
the sending of zero-length data, theOTSnd
function fails with thekOTBadDataErr
result.If the endpoint is in blocking mode, the
OTSnd
function returns after it actually sends the data. If flow-control restrictions prevent its sending the data, it retries the operation until it is able to send it. If the endpoint is in nonblocking mode, theOTSnd
function returns with thekOTFlowErr
result if flow-control restrictions prevent the data from being sent. When the endpoint provider is able to send the data, it returns aT_GODATA
event to let you know that it is possible to
send data.If the endpoint is in non-blocking or asynchronous mode, it is possible that only part of the data is actually accepted by the transport provider. In this case, the
OTSnd
function returns a value that is less than the value of thenbytes
parameter, or the errorkOTFlowErr
if no bytes at all were sent. After this error occurs, aT_GODATA
event will be issued when the flow control restrictions are lifted. This error is not returned if the endpoint is in blocking mode.If an asynchronous event, such as a disconnect, occurs and interrupts the
OTSnd
function,OTSnd
returns with thekOTLookErr
result.The following table shows how the endpoint's mode of execution and blocking status affects the behavior of the
OTSnd
function.
Blocking Nonblocking Synchronous The function returns when the provider lifts flow-control restrictions. The function returns immediately. The kOTFlowErr
result is never returned.The kOTFlowErr
result might be returned.Asynchronous The function returns immediately. The function returns immediately. The kOTFlowErr
result is never returned.The kOTFlowErr
result might be returned.SPECIAL CONSIDERATIONS
TheXTI_SNDLOWAT
option allows endpoints that support it to negotiate the minimum number of bytes that must have accumulated in the endpoint's internal send buffer before they are sent. If the endpoint you are using supports this option, you can negotiate a value using theOTOptionManagement
function. Because you use theOTOptionManagement
function to set this option, it affects all subsequent sends.VALID STATES
T_DATAXFER
,T_INREL
SEE ALSO
For information about transferring data, see "Using Connection-Oriented Transactionless Service," beginning on page 3-36.You can examine the
TEndpointInfo
structure (page 3-48) to find out what kind of data you can send and its maximum size.You use the
OTData
structure (page 3-52) to transfer noncontiguous data.For information on how to use this function with a TCP/IP protocol, see page 8-18 in the TCP/IP chapter.
For information on how to use this function with AppleTalk protocols, see page 13-11 in the ADSP chapter and page 15-10 in the PAP chapter.
For additional information about the
OTOptionManagement
function, see the chapter "Option Management" in this book.